home *** CD-ROM | disk | FTP | other *** search
/ Hottest 6 / Hottest 6 (1996)(PDSoft)[!].iso / software / fredfish / 1059.lha / Programs / MathPlot / Macros / GridLines.mapl < prev    next >
Text File  |  1994-12-15  |  4KB  |  258 lines

  1. /* Plots a grid. */
  2. /* Version 1.00, 07.08.1993 */
  3.  
  4. options results
  5.  
  6.  
  7. IF ~SHOW('L','rexxmathlib.library') THEN
  8.    CALL ADDLIB('rexxmathlib.library',0,-30)
  9.  
  10. /* OK, MathPlot will clear the screen before every plot when there */
  11. /* was no REAL plot before. So we have to do some trick to get a   */
  12. /* real plot....                                                   */
  13. /* If you do not understand this: Try this script and then plot    */
  14. /* another function or the axis. Then delete the next lines, clear */
  15. /* screen and do it again. The first time, you will se both        */
  16. /* functions, the second time only the last function.              */
  17.  
  18. getfunc 0
  19. a = result
  20.  
  21. setfunc 0 10000
  22. plot 0 normal
  23.  
  24. setfunc 0 a
  25.  
  26. /* End of trick.... */
  27.  
  28.  
  29.  
  30. /* First, get some infos from the program */
  31.  
  32. getintervall2 stem intervall.
  33. evalstring intervall.xmin
  34. xmn = result
  35. evalstring intervall.xmax
  36. xmp = result
  37. evalstring intervall.ymin
  38. ymn = result
  39. evalstring intervall.ymax
  40. ymp = result
  41. evalstring intervall.xminreal
  42. xmnr = result
  43. evalstring intervall.xmaxreal
  44. xmpr = result
  45. evalstring intervall.yminreal
  46. ymnr = result
  47. evalstring intervall.ymaxreal
  48. ympr = result
  49.  
  50. info stem b.
  51. colors = b.colors
  52.  
  53.  
  54.  
  55.  
  56. /* Calc the tics */
  57. xtics = maketics(xmn, xmp, 0, 10)
  58. ytics = maketics(ymn, ymp, 0, 10)
  59.  
  60. flx = floor(xmn/xtics)
  61. fly = floor(ymn/ytics)
  62. clx = ceil(xmp/xtics)
  63. cly = ceil(ymp/ytics)
  64.  
  65. /* Draw the tics */
  66. drawtics(xtics*flx, xtics, xtics*clx,
  67.         ,ytics*fly, ytics, ytics*cly)
  68. exit
  69.  
  70. /* ------------------------------------------------------------*/
  71. /* Function MakeTics */
  72. maketics:
  73. parse arg tmin, tmax, logscale, baselog
  74.  
  75. x = tmin-tmax
  76.  
  77. xr  = fabs(x)
  78. l10 = log10(xr)
  79. if(l10 >= 0.0) then do
  80.  i = floor(l10)
  81.  end
  82. else do
  83.  i = ceil(l10-1.0)
  84. end
  85.  
  86. if(logscale) then do
  87.   tic = raise(baselog, i)
  88.  if(tic < 1.0) then tic = 1.0
  89. end
  90. else do
  91.  xnorm = pow(10.0, l10-i)
  92.  if(xnorm <= 2.01) then do
  93.   tics = 0.2
  94.   end
  95.  else do
  96.   if(xnorm <= 5) then do
  97.    tics = 0.5
  98.    end
  99.   else do
  100.    tics = 1.0
  101.   end
  102.  end
  103.   tic = tics * raise(10.0,i)
  104. end
  105. return tic
  106.  
  107.  
  108. /* ------------------------------------------------------------*/
  109. /* Function RAISE */
  110. raise:
  111. parse arg x,y
  112.  
  113. val = 1.0
  114. do i=0 to abs(y)-1
  115.  val = val*x
  116. end
  117.  
  118. if(y < 0) then val = 1/val
  119.  
  120. return val
  121.  
  122.  
  123. /* ------------------------------------------------------------*/
  124. /* DrawTics */
  125. drawtics:
  126. parse arg xstart, xdiff, xendorig, ystart, ydiff, yendorig
  127.  
  128.  
  129. /* Round a bit */
  130. xend = xendorig * 1.001
  131. yend = yendorig * 1.001
  132.  
  133. a = 0
  134. b = 0
  135.  
  136. e    = exp(1)
  137. pi   = 2*acos(0)
  138. ln10 = ln(10)
  139.  
  140.  
  141. select
  142.  when intervall.xmode=0 then do
  143.   do pos1 = xstart to xend by xdiff
  144.    x.a   = pos1
  145.    a   = a+1
  146.   end
  147.  end
  148.  when intervall.xmode=1 then do
  149.   do pos1 = xstart to xend by xdiff
  150.    x.a   = pos1*e
  151.    a   = a+1
  152.   end
  153.  end
  154.  when intervall.xmode=2 then do
  155.   do pos1 = xstart to xend by xdiff
  156.    x.a   = pos1*pi
  157.    a   = a+1
  158.   end
  159.  end 
  160.  when intervall.xmode=3 then do
  161.   do pos1 = xstart to xend by xdiff
  162.    x.a   = exp(pos1)
  163.    a   = a+1
  164.   end
  165.  end 
  166.  when intervall.xmode=4 then do
  167.   do pos1 = xstart to xend by xdiff
  168.    x.a   = exp(pos1*ln10)
  169.    a   = a+1
  170.   end
  171.  end 
  172.  otherwise nop
  173. end
  174.  
  175.  
  176. select
  177.  when intervall.ymode=0 then do
  178.   do pos1 = ystart to yend by ydiff
  179.    y.b   = pos1
  180.    b   = b+1
  181.   end
  182.  end
  183.  when intervall.ymode=1 then do
  184.   do pos1 = ystart to yend by ydiff
  185.    y.b   = pos1*e
  186.    b   = b+1
  187.   end
  188.  end
  189.  when intervall.ymode=2 then do
  190.   do pos1 = ystart to yend by ydiff
  191.    y.b   = pos1*pi
  192.    b   = b+1
  193.   end
  194.  end 
  195.  when intervall.ymode=3 then do
  196.   do pos1 = ystart to yend by ydiff
  197.    y.b   = exp(pos1)
  198.    b   = b+1
  199.   end
  200.  end 
  201.  when intervall.ymode=4 then do
  202.   do pos1 = ystart to yend by ydiff
  203.    y.b   = exp(pos1*ln10)
  204.    b   = b+1
  205.   end
  206.  end 
  207.  otherwise nop
  208. end
  209.  
  210.  
  211.  
  212.  
  213. /* Reset plotcolor */
  214. getcolor plotcolor
  215. oldcolor = result
  216.  
  217. /* Ask plotcolor */
  218. /* First generate the button-string */
  219. select
  220.  when colors = 2 then do
  221.   but = "1|Cancel"
  222.  end
  223.  when colors = 4 then do
  224.   but = "1|2|3|Cancel"
  225.  end
  226.  when colors = 8 then do
  227.   but = "1|2|3|4|5|6|7|Cancel"
  228.  end
  229.  when colors = 16 then do 
  230.   but = "1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|Cancel"
  231.  end
  232.  when colors = 32 then do
  233.   /* 32 colors does not make sense here */
  234.   but = "1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|Cancel"
  235.  end
  236. end
  237.  
  238. text = 'title "GridLines" prompt "Select a color" button ' || but
  239.  
  240. /* Now ask */
  241. requestresponse text
  242.  
  243. if RC == 5 then exit
  244.  
  245. setcolor plotcolor result
  246.  
  247. /* Plot the grid */
  248. do i=0 to a-1
  249.     line x.i ympr x.i ymnr
  250. end
  251. do j=0 to b-1
  252.     line xmnr y.j xmpr y.j
  253. end
  254.  
  255. setcolor plotcolor oldcolor
  256.  
  257. return 0
  258.